<template>
    <div class="app-container">
        <uc-table url="/admin/enterpriseTask/getEnterpriseTaskInfoPage" name="任务详情" ref="taskInfoTable" pageable table-border :search-form="searchForm">
            <template slot="searchForm">
                <el-form size="mini" :inline="true" :model="searchForm" class="demo-form-inline filter-container">
                    <el-form-item v-if="enterPriseHidden">
                        <el-select v-model="searchForm.enterpriseId" placeholder="请选择企业" style="width: 100%">
                            <el-option v-for="(item,index) in enterpriseList" :key="index"  :value="item.ucId" :label="item.enterpriseName"></el-option>
                        </el-select>
                    </el-form-item>
                    <!--搜索按钮--新增按钮-->
                    <el-form-item>
                        <el-button type="primary" icon="el-icon-search" class="filter-item" @click="handleSearch()">查询</el-button>
                    </el-form-item>
                </el-form>
            </template>
            <template slot="columns">
                <el-table-column prop="taskName" label="任务ID" align="left" :show-overflow-tooltip="true"></el-table-column>
                <el-table-column prop="enterpriseName" label="企业Id" align="left" :show-overflow-tooltip="true"></el-table-column>
                <el-table-column prop="status" label="任务状态" align="left">
                    <template slot-scope="scope">
                        {{scope.row.status| taskStatus}}
                    </template>
                </el-table-column>j
                <el-table-column prop="feedBack" label="反馈内容" align="left" :show-overflow-tooltip="true"></el-table-column>
                <el-table-column prop="startTime" label="开始时间" align="left" :show-overflow-tooltip="true"></el-table-column>
                <el-table-column prop="endTime" label="结束时间" align="left" :show-overflow-tooltip="true"></el-table-column>
                <el-table-column prop="address" label="操作" width="220" align="left" class-name="small-padding fixed-width">
                    <template slot-scope="scope">
                        <!--编辑按钮-->
                        <el-button size="mini" icon="el-icon-edit" type="primary" @click="handleEdit(scope.row)">编辑</el-button>
                        <el-button size="mini" icon="el-icon-info" type="success" @click="handleInfo(scope.row)">详情</el-button>
                    </template>
                </el-table-column>
            </template>
        </uc-table>
    </div>
</template>

<script>
import UcTable from "@/components/UcTable/index.vue";
import {deleteInTaskRelease} from "@/api/enterpriseTask";
import {getInEnterpriseList} from "@/api/enterprise";


export default {
    name: "UserTaskList",
    components: {UcTable},
    data(){
        return{
            searchForm:{
                deleted:false,
            },
            deleteLoading:false,
            enterpriseList:[

            ]
        }
    },
  computed:{
    enterPriseHidden(){
      let roleCode = this.$store.getters.roleCode;
      return roleCode=="ADMIN"||roleCode=="XT-ADMIN"||roleCode=="ZD-ADMIN"||roleCode=="DD-ADMIN"||roleCode=="JW-ADMIN"
    }
  },
    created() {
        this.getInEnterpriseList()
    },
    methods:{
        handleSearch(){
            this.$refs.taskReleaseTable.getTableData(1)
        },
        handleEdit(val){
            this.$router.push("/enterpriseTask/taskInfoEdit/"+val.ucId)
        },
        handleInfo(val){
            this.$router.push("/enterpriseTask/taskInfoInfo/"+val.ucId)
        },
        clearInput(){
            //清除输入框
            this.searchForm.name = null
            this.handleSearch()
        },
        getInEnterpriseList(){
            getInEnterpriseList({deleted:false}).then(res=>{
                this.enterpriseList = res.data
            }).catch(error=>{

            })
        }
    },
    filters:{
        taskTypeStatus(val){
            let taskType = "";
            switch (val){
                case 0:
                    taskType = "消防演练";
                    break;
                case 1:
                    taskType = "巡检任务";
                    break;
                case 2:
                    taskType = "培训任务";
                    break;
                case 3:
                    taskType = "维保任务";
                    break;
                default:
                    break;
            }
            return taskType;

        },
        taskStatus(val){
            let status ="";
            switch (val){
                case 0:
                    status = "已下发";
                    break;
                case 1:
                    status = "进行中";
                    break;
                case 2:
                    status = "延迟";
                    break;
                case 3:
                    status = "已完成";
                    break;
                case 4:
                    status = "已取消";
                    break;
                default:
                    break;
            }
            return status;
        }
    }

}
</script>

<style scoped>

</style>